package com.test.schoolhelper.app;

import android.app.Application;
import android.content.Context;

import com.liulishuo.filedownloader.FileDownloader;
import com.liulishuo.filedownloader.connection.FileDownloadUrlConnection;
import com.test.schoolhelper.db.DbUserController;
import com.test.schoolhelper.entity.User;
import com.test.schoolhelper.utils.Tools;

import java.util.ArrayList;
import java.util.List;

// TODO: 2024/5/29 app
public class App extends Application {

    private static Context context;

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
        new Thread(() -> {
            initDB();
        }).start();

        initDownLoad();
    }

    private void initDownLoad() {
        FileDownloader.setupOnApplicationOnCreate(this)
                .connectionCreator(new FileDownloadUrlConnection
                        .Creator(new FileDownloadUrlConnection.Configuration()
                        .connectTimeout(15000) // set connection timeout.
                        .readTimeout(15000) // set read timeout.
                ))
                .commit();
    }


    public static Context getContext() {
        return context;
    }
    private List<User> list = new ArrayList<>();
    private void initDB() {
        list=DbUserController.getInstance(this).searchAll();
        if (list.size()==0){
            User user = new User("张三", Tools.generatePhoneNumber(), "京东","北京市朝阳区");
            DbUserController.getInstance(this).insertOrReplace(user);
        }

    }

}


